package com.objectproject.main.controller;

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.objectproject.main.dao.MyLocaleDAOImpl;
import com.objectproject.main.dao.MyObjectDAOImpl;
import com.objectproject.main.dao.MyPrimitiveDAOImpl;
import com.objectproject.main.enumeration.ValueType;
import com.objectproject.main.exception.PropertyRefineException;
import com.objectproject.main.model.MyObjectCommandModel;
import com.objectproject.main.service.subsystem.MyLocaleResolver;

/**
 * Handles requests for the application home page.
 */
@Controller
public class ObjectController {
	
	@Autowired
	MyObjectDAOImpl myObjectDAOImpl;
	
	@Autowired
	MyPrimitiveDAOImpl myPrimitiveDAOImpl;
	
	@Autowired
	MyLocaleDAOImpl myLocaleDAOImpl;
	
	@Autowired
	MyLocaleResolver myLocaleResolver;
	
	
	private static final Logger logger = LoggerFactory.getLogger(ObjectController.class);
	
	/**
	 * Simply selects the home view to render by returning its name.
	 * @throws PropertyRefineException 
	 */
	@RequestMapping(value = "/createObject", method = RequestMethod.POST)
	public String home(@ModelAttribute MyObjectCommandModel myObjectCommandModel, HttpServletRequest request, HttpServletResponse response, Locale locale, Model model) throws PropertyRefineException {
		logger.info("Welcome home! The client locale is {}.", locale);
		
		myObjectCommandModel.refine();
		
		System.out.println(myObjectCommandModel);
		
		return "index";
	}
	
	@RequestMapping(value = "/createObjectForm")
	public ModelAndView home(Locale locale, Model model) {
		logger.info("home");
		
		return new ModelAndView("createObjectForm", "myObjectCommandModel", new MyObjectCommandModel());
		
		
		//return "creationFormObject";
	}
	
}

